package com.jojo.common.utils;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

public class BeanCopyUtils {

    /**
     *
     * @param source  原vo
     * @param clavv  要复制到的entity
     * @param <V> 返回值类型参数 为 V 同 classV结果相同；
     * @return
     */
    public static <V>  V copyBean(Object source,Class<V> clavv){
        V result =null;
        try {
            result = clavv.newInstance();
            BeanUtils.copyProperties(source,result);
        } catch (Exception e) {
            e.printStackTrace();
        }
          return result;

    }
    public static <O,V> List<V> copyBeanList(List<O> sourcelist,Class<V> clavv){
        List<V> resultList = sourcelist.stream().map(result ->
                copyBean(result, clavv)
        ).collect(Collectors.toList());

        return resultList;

    }
}
